package com.panopset.refactorsf;

import javax.swing.JCheckBox;

import com.panopset.java.Version;
import com.panopset.sf.FontManager.FontType;
import com.panopset.sf.FontManager;
import com.panopset.sf.Windoc;

/**
 * JCheckBox persistent container.
 * 
 * @author Karl Dinwiddie
 * 
 */
public final class PanCheckBox extends PanNoBorderField<JCheckBox> {

	private final String lbl;

	public PanCheckBox(final Windoc wd, final String label,
			final String toolTipText, final boolean dft, final String key) {
		super(wd, new Boolean(dft).toString(), toolTipText, key);
		lbl = label;
	}

	@Override
	protected String getGuiValue() {
		return Boolean.valueOf(getInnerComponent().isSelected()).toString();
	}

	@Override
	protected void setGuiValue(String value) {
		getInnerComponent().setSelected(Boolean.parseBoolean(value));
	}

	@Override
	public JCheckBox createComponent() {
		JCheckBox rtn = new JCheckBox(lbl);
		rtn.setBackground(LookAndFeel.Colors.BG_COLOR.getColor());
		FontManager.getInstance().register(rtn, FontType.plainArial);
		return rtn;
	}

	@Override
	protected boolean isValid(final String valueToCheck) {
		return true;
	}

	public boolean isSelected() {
		return isChecked();
	}

	/**
	 * @return True iff user checked this box.
	 */
	public boolean isChecked() {
		return getInnerComponent().isSelected();
	}
}
